package com.hmall.cart.listener;
/*
  Date: 2023/11/29
  Author: Luochao
  Description:
*/

import com.hmall.cart.service.ICartService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Collection;


@Component
@RequiredArgsConstructor
public class CartListener {
    private final ICartService cartService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "cart.removeByItemIds",durable = "true"),
            exchange = @Exchange(name = "hmall.cart",type = ExchangeTypes.FANOUT),
            key = {"removeByItemIds"}
    ))

    public void listenRemoveByIdsQueue(Collection<Long> itemIds) {
        System.out.println("消费者2 收到了 hmall.cart的消息：【" + itemIds +"】");
        cartService.removeByItemIds(itemIds);

    }
}
